home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / HEDGE11.ZIP / COMMON.C next >
Text File  |  1995-02-12  |  6KB  |  212 lines

  1. /****************************************************************************\
  2. *                                                                            *
  3. *  COMMON.C                                                                  *
  4. *                                                                            *
  5. *  general purpose functions used in Hedge Row                               *
  6. *                                                                            *
  7. \****************************************************************************/
  8.  
  9. #define common_c
  10. #include "defs.h"
  11.  
  12. /****************************************************************************\
  13. *                                                                            *
  14. *  abort_game -- exit to DOS if a file or item is not found                  *
  15. *                                                                            *
  16. \****************************************************************************/
  17.  
  18. void abort_game()
  19. {
  20.  
  21.    /* free the mouse handler and extra pages */
  22.  
  23.    fg_mousefin();
  24.    fg_freepage(SPARE);
  25.  
  26.    /* set the video mode and reset screen attributes */
  27.  
  28.    fg_setmode(3);
  29.    fg_reset();
  30.  
  31.    /* print out the abort string and exit */
  32.  
  33.    printf(abort_string);
  34.    printf("\n");
  35.    exit(0);
  36. }
  37.  
  38. /****************************************************************************\
  39. *                                                                            *
  40. *  center_string -- use ROM font, center around a point                      *
  41. *                                                                            *
  42. \****************************************************************************/
  43.  
  44. void center_string(char *string, int x, int y)
  45. {
  46.    int nchar;
  47.    int x1;
  48.  
  49.    /* measure the length of the string */
  50.  
  51.    nchar = strlen(string);
  52.  
  53.    /* calculate the x position */
  54.  
  55.    x1 = x - nchar*4;
  56.    if (x1 < 0) x1 = 0;
  57.  
  58.    /* move to the location and print the string */
  59.  
  60.    fg_move(x1,y);
  61.    fg_print(string,nchar);
  62. }
  63.  
  64. /****************************************************************************\
  65. *                                                                            *
  66. *  flushkey -- flush out the keystroke buffer                                *
  67. *                                                                            *
  68. \****************************************************************************/
  69.  
  70. void flushkey()
  71. {
  72.    unsigned char key,aux;
  73.  
  74.    /* just keep reading keys until there aren't any */
  75.  
  76.    do
  77.       fg_intkey(&key,&aux);
  78.    while (key+aux > 0);
  79. }
  80.  
  81. /****************************************************************************\
  82. *                                                                            *
  83. *  init_graphics -- initialize the graphics environment                      *
  84. *                                                                            *
  85. \****************************************************************************/
  86.  
  87. void init_graphics()
  88. {
  89.    int status;
  90.  
  91.    /* in case we're compiling for protected mode */
  92.  
  93.    fg_initpm();
  94.  
  95.    /* initialize the SVGA kernel */
  96.  
  97.    if (fg_svgainit(0) == 0)
  98.    {
  99.       strcpy(abort_string,"This program requires SVGA.");
  100.       abort_game();
  101.    }
  102.  
  103.    /* make sure an 800x600x256 mode with two pages is available */
  104.  
  105.    if (fg_testmode(26,2) == 0)
  106.    {
  107.       strcpy(abort_string,"This program requires a 1MB SVGA.");
  108.       abort_game();
  109.    }
  110.  
  111.    /* find out what the old video mode is */
  112.  
  113.    old_mode = fg_getmode();
  114.  
  115.    /* initialize 800x600x256 graphics */
  116.  
  117.    fg_setmode(26);
  118.  
  119.    /* find room for another page somewhere */
  120.    /* try XMS and EMS for real mode        */
  121.  
  122.    status = fg_initxms();
  123.    if (status == 0)
  124.       status = fg_allocxms(SPARE);
  125.  
  126.    if (status < 0)
  127.    {
  128.       status = fg_initems();
  129.       if (status == 0)
  130.          status = fg_allocems(SPARE);
  131.       if (status < 0)
  132.          status = fg_alloccms(SPARE);
  133.    }
  134.  
  135.    if (status < 0)
  136.    {
  137.       strcpy(abort_string,"This program requires XMS or EMS memory.");
  138.       abort_game();
  139.    }
  140.  
  141.    /* benchmark the microprocessor for consistent stall times */
  142.  
  143.    clockspeed = fg_measure();
  144.  
  145.    /* initialize the mouse */
  146.  
  147.    init_mouse();
  148. }
  149.  
  150. /****************************************************************************\
  151. *                                                                            *
  152. *  init_mouse -- initialize the mouse if present                             *
  153. *                                                                            *
  154. \****************************************************************************/
  155.  
  156. void init_mouse()
  157. {
  158.    if (fg_mouseini() > 0)
  159.    {
  160.       mouse = TRUE;
  161.       xmouse = 160;
  162.       ymouse = 100;
  163.       fg_mousemov(xmouse,ymouse);
  164.       fg_mousespd(4,8);
  165.    }
  166.    else
  167.    {
  168.       strcpy(abort_string,"This program requires a mouse.");
  169.       abort_game();
  170.    }
  171. }
  172.  
  173. /****************************************************************************\
  174. *                                                                            *
  175. *  put_string -- put ROM font at an x and y position on the screen           *
  176. *                                                                            *
  177. \****************************************************************************/
  178.  
  179. void put_string(char *string,int x,int y)
  180. {
  181.    int nchar;
  182.  
  183.    /* determine the length of the string */
  184.  
  185.    nchar = strlen(string);
  186.  
  187.    /* move to desired location and display it */
  188.  
  189.    fg_move(x,y);
  190.    fg_print(string,nchar);
  191. }
  192.  
  193. /****************************************************************************\
  194. *                                                                            *
  195. *  quit_graphics -- return the computer to its original state                *
  196. *                                                                            *
  197. \****************************************************************************/
  198.  
  199. void quit_graphics()
  200. {
  201.    /* free the mouse handler and allocated page */
  202.  
  203.    fg_mousefin();
  204.    fg_freepage(SPARE);
  205.  
  206.    /* reset the mode, fix screen attributes, and exit */
  207.  
  208.    fg_setmode(old_mode);
  209.    fg_reset();
  210.    exit(0);
  211. }
  212.